package com.team2.outpatient_sys.dao;

import com.team2.outpatient_sys.pojo.PharmacyStorage;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PharmacyStorageDao {
    //增加库存
    @Insert("insert into pharmacy_storage(deadline,cont,medicine_id,name,category,price,brand,date_manufacture) values(#{deadline},#{cont},#{medicineId},#{name},#{category},#{price},#{brand},#{dateManufacture})")
    public Integer add(PharmacyStorage pharmacyStorage);

    @Select("select * from pharmacy_storage where name = #{name}")
    public PharmacyStorage findByName(String name);

    //根据名字来更新药品的数量和日期
    @Update("update pharmacy_storage set cont = #{cont}+cont,date_manufacture = #{dateManufacture} where name = #{name}")
    Integer updateByName(PharmacyStorage pharmacyStorage);

    //库存不足预警
    @Select("select * from pharmacy_storage where cont<100")
    public List<PharmacyStorage> findByCont();

    @Select("select * from pharmacy_storage")
    List<PharmacyStorage> findAll();

    //逾期处理减少库存
    @Update("update pharmacy_storage set cont=cont-#{cont} where medicine_id=#{medicineId}")
    public void update(@Param("cont") Integer cont , @Param("medicineId") Integer medicineId);


}
